#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int n = prices.size();
        vector<int> dp(n, 0);
        int min = prices[0];
        for (int i = 1; i < n; i++)
        {
            dp[i] = max(dp[i - 1], prices[i] - min);
            if (min > prices[i])
            {
                min = prices[i];
            }
        }
        return dp[n - 1];


    }
};